home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6623 / 6623.xpi / content / bpopt.js < prev    next >
Text File  |  2010-01-05  |  13KB  |  410 lines

  1.  
  2.  
  3.  
  4.  
  5. var bpopt = {
  6.     WindowObjectReference: null,
  7.     prompts: Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService),
  8.     prefs: Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.bprivacy."),
  9.  
  10.     HelpPageDisplay: function(page)
  11.     {
  12.         if(bpopt.WindowObjectReference == null || bpopt.WindowObjectReference.closed)
  13.         {
  14.             try{
  15.                 bpopt.WindowObjectReference = window.open(page, "", "width=800,height=600,alwaysRaised=yes,resizable=yes,scrollbars=yes,status=no");
  16.             }catch(e){;}
  17.         }
  18.     },
  19.  
  20.  
  21.     //Options window opened
  22.     init: function()
  23.     {
  24.  
  25.         try{
  26.  
  27.         window.sizeToContent();
  28.  
  29.         bpriv.LSOTreeShow(bpriv.GetFlashDir(0));
  30.  
  31.         if( 
  32.             ( !navigator.preference("extensions.bprivacy.sendpings.allowed") && (navigator.preference("extensions.bprivacy.sendpings.allowed") != navigator.preference("browser.send_pings")) )
  33.         )
  34.         {
  35.             if(confirm("BetterPrivacy:\r\nThe addon detected that one or more privacy settings have been modified!\r\nPress OK to correct those values.")){
  36.                 navigator.preference("browser.send_pings", navigator.preference("extensions.bprivacy.sendpings.allowed"));
  37.             }
  38.         }
  39.         var interval = navigator.preference("extensions.bprivacy.DelTimerInterval");
  40.         var selidx = 2;
  41.         var val = 1;
  42.         if(interval % 86400 == 0){//days
  43.             val = interval / 86400;
  44.             selidx = 3;
  45.         }else if(interval % 3600  == 0){ //hours
  46.             val = interval / 3600;
  47.             selidx = 2;
  48.         }else if(interval % 60 == 0){ //minutes
  49.             val = interval / 60;
  50.             selidx = 1;
  51.         }else if(interval >= 1){
  52.             val = Math.round(interval);
  53.             selidx = 0;
  54.         }
  55.         document.getElementById("delInterval").value = val;
  56.         document.getElementById("unitList").selectedIndex = selidx;
  57.  
  58.         document.getElementById("AutoDelLSOnExitModeID").selectedIndex = navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode");
  59.         if(bpopt.isSeaMonkey)
  60.             document.getElementById("DelLSONoDialog").label = "Do nothing";
  61.  
  62.         var sinceDate = bpriv.getString("since") + " ";
  63.         try{
  64.             sinceDate += bpopt.prefs.getComplexValue("lastSession", Components.interfaces.nsISupportsString).data; //new format may not be available the first time
  65.         }catch(e){sinceDate += navigator.preference("extensions.bprivacy.lastSession");}
  66.         document.getElementById("SessionLabelID").value = sinceDate;
  67.  
  68.         document.getElementById("KeyCodeLabel").value = navigator.preference("extensions.bprivacy.keymodifiers") + " + ";
  69.         if(navigator.preference("extensions.bprivacy.keycode"))
  70.             document.getElementById ("KeyCodeBox").value = String.fromCharCode(navigator.preference("extensions.bprivacy.keycode"));
  71.  
  72.         bpopt.AutoIntervalToggled();
  73.         bpopt.AutoDelLSOToggled();
  74.         bpopt.AlwaysReScanToggled(false);
  75.         bpopt.NotifyOnNewLSOToggled();
  76.  
  77.         document.getElementById("MacAcceptBtn").focus();
  78.         }catch(e){alert("An error occured while opening BetterPrivacy\r\nPlease send the following information to the author: \r\n"+e);}
  79.     },
  80.  
  81.     
  82.    _isSeaMonkey: null,
  83.    get isSeaMonkey() {
  84.     if (this._isSeaMonkey == null) {
  85.         var appInfo=Components.classes["@mozilla.org/xre/app-info;1"]
  86.                 .getService(Components.interfaces.nsIXULAppInfo);
  87.         this._isSeaMonkey = appInfo.name == 'SeaMonkey';
  88.      }
  89.      return this._isSeaMonkey;
  90.    },
  91.  
  92.  
  93.  
  94.     accept: function(byButton)
  95.     {
  96.         if(document.getElementById("alwaysReScanPref").checked)
  97.             navigator.preference("extensions.bprivacy.alwaysReScan", true);
  98.         else
  99.             navigator.preference("extensions.bprivacy.alwaysReScan", false);
  100.  
  101.         if(document.getElementById("AutoDelLSOOnStartPref").checked)
  102.             navigator.preference("extensions.bprivacy.AutoDelLSOnStart", true);
  103.         else
  104.             navigator.preference("extensions.bprivacy.AutoDelLSOnStart", false);
  105. /*
  106.         if(document.getElementById("AutoDelLSOPref").checked)
  107.             navigator.preference("extensions.bprivacy.AutoDelLSO", true);
  108.         else
  109.             navigator.preference("extensions.bprivacy.AutoDelLSO", false);
  110. */
  111.         if(document.getElementById("AutoDelLSOnExitModeID").selectedIndex >= 0)
  112.             navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode", document.getElementById("AutoDelLSOnExitModeID").selectedIndex);
  113.  
  114.         if(document.getElementById("AskOnExitPref").checked)
  115.             navigator.preference("extensions.bprivacy.donotaskonexit", false);
  116.         else
  117.             navigator.preference("extensions.bprivacy.donotaskonexit", true);
  118.  
  119.  
  120.         if(document.getElementById("AutoDelIntervalPref").checked){
  121.             navigator.preference("extensions.bprivacy.useDelTimer", true);
  122.         }else{
  123.             navigator.preference("extensions.bprivacy.useDelTimer", false);
  124.         }
  125.  
  126.  
  127.         if(document.getElementById("AutoDelIntervalDelayPref").checked){
  128.             navigator.preference("extensions.bprivacy.useDelTimerDelay", true);
  129.         }else{
  130.             navigator.preference("extensions.bprivacy.useDelTimerDelay", false);
  131.         }
  132.  
  133.  
  134.         if(document.getElementById("AutoDelDCPref").checked){
  135.             navigator.preference("extensions.bprivacy.DefaultFlashCookieDeletion", true);
  136.         }else{
  137.             navigator.preference("extensions.bprivacy.DefaultFlashCookieDeletion", false);
  138.         }
  139.  
  140.  
  141.         if(document.getElementById("AutoDelDirsPref").checked){
  142.             navigator.preference("extensions.bprivacy.delDirs", true);
  143.         }else{
  144.             navigator.preference("extensions.bprivacy.delDirs", false);
  145.         }
  146.  
  147.         if(document.getElementById("NotifyOnNewLSOPref").checked){
  148.             navigator.preference("extensions.bprivacy.NotifyOnNewLSO", 2);
  149.         }else{
  150.             navigator.preference("extensions.bprivacy.NotifyOnNewLSO", 0);
  151.         }
  152.  
  153.         navigator.preference("extensions.bprivacy.NotifyDuration", parseInt(document.getElementById("NotifyDurationID").value));
  154.  
  155.         if(document.getElementById("ClearDOMPref").checked){
  156.             navigator.preference("extensions.bprivacy.domclear", true);
  157.         }else{
  158.             navigator.preference("extensions.bprivacy.domclear", false);
  159.         }
  160. /*
  161.         if(document.getElementById("DisableDOMPref").checked){
  162.             navigator.preference("extensions.bprivacy.domstorage.allowed", false);
  163.             navigator.preference("dom.storage.enabled", false);
  164.         }else{
  165.             navigator.preference("extensions.bprivacy.domstorage.allowed", true);
  166.             navigator.preference("dom.storage.enabled", true);
  167.         }
  168. */
  169.         if(document.getElementById("DisablePingPref").checked){
  170.             navigator.preference("browser.send_pings", false);
  171.             navigator.preference("extensions.bprivacy.sendpings.allowed", false);
  172.         }else{
  173.             navigator.preference("browser.send_pings", true);
  174.             navigator.preference("extensions.bprivacy.sendpings.allowed", true);
  175.         }
  176.  
  177.         var interval = document.getElementById("delInterval").value;
  178.         var idx = document.getElementById("unitList").selectedIndex;
  179.         var factor = 60 * 60; //default hours
  180.         if(idx == 0)
  181.             factor = 1; //seconds
  182.         else if(idx == 1)
  183.             factor = 60;  //minutes
  184.         else if(idx == 2)
  185.             factor = 60 * 60; //hours
  186.         else if(idx == 3)
  187.             factor = 60 * 60 * 24; //days
  188.         interval = interval * factor;
  189.         navigator.preference("extensions.bprivacy.DelTimerInterval", interval);
  190.         navigator.preference("extensions.bprivacy.removedSession", 0);//statistics
  191.         var cDate = new Date();
  192.         //navigator.preference("extensions.bprivacy.lastSession", cDate.toLocaleString());//for statistics
  193.         var localDate = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  194.         localDate.data = cDate.toLocaleString();
  195.         bpopt.prefs.setComplexValue("lastSession", Components.interfaces.nsISupportsString, localDate);//for statistics
  196.  
  197.         var keycodeBox = document.getElementById ("KeyCodeBox");
  198.         if(keycodeBox){
  199.             var value = keycodeBox.value ? keycodeBox.value.charCodeAt(0) : 0;
  200.             navigator.preference("extensions.bprivacy.keycode", value);
  201.         }
  202.         bpriv.SetKeys();
  203.     },
  204.  
  205.  
  206.  
  207.  
  208.     AutoDelLSOToggled: function()
  209.     {
  210. /*
  211.         if(document.getElementById("AutoDelLSOPref").checked)
  212.             document.getElementById("AskOnExitPref").disabled = false;
  213.         else
  214.             document.getElementById("AskOnExitPref").disabled = true;
  215. */
  216.         if(!document.getElementById("AutoDelLSOnExitModeID").selectedIndex)
  217.             document.getElementById("AskOnExitPref").disabled = false;
  218.         else
  219.             document.getElementById("AskOnExitPref").disabled = true;
  220.     },
  221.  
  222.  
  223.     AutoIntervalToggled: function()
  224.     {
  225.             if(document.getElementById("AutoDelIntervalPref").checked == false){
  226.                 document.getElementById("AutoDelIntervalDelayPref").disabled = true;
  227.                 document.getElementById("delIntervallabel").disabled = true;
  228.                 document.getElementById("delInterval").disabled = true;
  229.                 document.getElementById("unitList").disabled = true;
  230.             }else{
  231.                 document.getElementById("AutoDelIntervalDelayPref").disabled = false;
  232.                 document.getElementById("delIntervallabel").disabled = false;
  233.                 document.getElementById("delInterval").disabled = false;
  234.                 document.getElementById("unitList").disabled = false;
  235.             }
  236.     },
  237.  
  238.  
  239.     AlwaysReScanToggled: function(byButton)
  240.     {
  241.             
  242.             if(byButton && document.getElementById("alwaysReScanPref").checked == true)
  243.             {
  244.                 if(!confirm(bpriv.getString("alwaysRescan")))
  245.                     document.getElementById("alwaysReScanPref").checked = false;
  246.             }
  247.             if(document.getElementById("alwaysReScanPref").checked == false){
  248.                 document.getElementById("selectFolderID").disabled = false;
  249.             }else{
  250.                 document.getElementById("selectFolderID").disabled = true;
  251.             }
  252.     },
  253.  
  254.  
  255.  
  256.     propagateToggled: function()
  257.     {
  258.         navigator.preference("extensions.bprivacy.propagate", !navigator.preference("extensions.bprivacy.propagate"));
  259.         bpriv.setPropagation();
  260.     },
  261.  
  262.  
  263.  
  264.  
  265.     NotifyOnNewLSOToggled: function(byuser)
  266.     {
  267.         if(document.getElementById("NotifyOnNewLSOPref").checked == true){
  268.             var message = bpriv.getString("constantparsingwarning");
  269.             if(byuser && !bpopt.prompts.confirm(null, "BetterPrivacy Warning", message))
  270.             {
  271.                 document.getElementById("NotifyOnNewLSOPref").checked = false;
  272.                 return;
  273.             }
  274.             document.getElementById("NotifyDurationID").disabled = false;
  275.         }else{
  276.             document.getElementById("NotifyDurationID").disabled = true;
  277.         }
  278.     },
  279.  
  280.  
  281.     initPL: function()
  282.     {
  283.         arrList = navigator.preference("extensions.bprivacy.protectedLSOList").split("|");
  284.         var listBox = document.getElementById ("listBox");
  285.         for (var j=0;j<arrList.length;j++) {
  286.                 try{
  287.                         var val = "";
  288.                         val = arrList.slice(j,j+1).toString();
  289.                         if(val.length > 0)
  290.                             listBox.appendChild (bpopt.newListItem (val, val));
  291.                 }catch(e){}
  292.         }
  293.         arrList = null;
  294.     },
  295.  
  296.  
  297.  
  298.     acceptPL: function()
  299.     {
  300.             var list = [];
  301.             var listBox = document.getElementById ("listBox");
  302.             var rows = listBox.getRowCount ();
  303.             for (var n = 0; n < rows; n++)
  304.             {
  305.                 var listitem = listBox.getItemAtIndex (n);
  306.                 var listcell = listitem.childNodes.item (0);
  307.                 var value = listcell.getAttribute("value").replace(/[\\\/]$/i, "");
  308.                 list.push (value);
  309.             }
  310.             navigator.preference("extensions.bprivacy.protectedLSOList", list.join("|").toString());
  311.     },
  312.  
  313.     
  314.     EditPL: function()
  315.     {
  316.         //modal window
  317.         window.open("chrome://bp/content/editpl.xul", "", "chrome=yes,modal=yes,resizable=yes,width=750,height=350");
  318.  
  319.         //bpriv.LSOTreeShow(bpriv.GetFlashDir(0));
  320.         bpriv.RefreshLSOProtection();
  321.         bpriv.updateGUI(bpriv.GetFlashDir(0), false);
  322.         bpriv.TreeOnSelect();
  323.     },
  324.  
  325.  
  326.     newListItem: function (label, value)
  327.     {
  328.         var row = document.createElement ("listitem");
  329.         row.setAttribute ("allowevents", true);
  330.         var cell = document.createElement ("listcell");
  331.         cell.setAttribute ("id", "");
  332.         cell.setAttribute ("label", label);
  333.         cell.setAttribute ("value", value);
  334.         row.appendChild (cell);
  335.         return row;
  336.     },
  337.  
  338.  
  339.     listTextboxOnInput: function  (event)
  340.     {
  341.         var add = document.getElementById ("listAdd");
  342.         var textbox = event.target;
  343.         if (0 < textbox.textLength)
  344.         {
  345.             add.removeAttribute ("disabled");
  346.         }
  347.         else
  348.         {
  349.             add.setAttribute ("disabled", true);
  350.         }
  351.     },
  352.  
  353.     listBoxOnSelect: function  (event)
  354.     {
  355.         document.getElementById ("listEdit").removeAttribute ("disabled");
  356.         document.getElementById ("listRemove").removeAttribute ("disabled");
  357.     },
  358.  
  359.  
  360.     listAddOnCommand: function  (event)
  361.     {
  362.         var textbox = document.getElementById ("listTextbox");
  363.         if(textbox.value.length < 2){
  364.             alert("Input too short");
  365.             return;
  366.         }
  367.         var listBox = document.getElementById ("listBox");
  368.         listBox.appendChild (bpopt.newListItem (textbox.value, textbox.value));
  369.     },
  370.  
  371.  
  372.     listEditOnCommand: function  (event)
  373.     {
  374.         var listBox = document.getElementById ("listBox");
  375.         if (listBox.selectedItem == null)
  376.             return;
  377.         var listcell = listBox.selectedItem.childNodes.item (0);
  378.         var inout = { value: listcell.getAttribute ("value") };
  379.         bpopt.prompts.prompt(window, "", "", inout, null, { value: false });
  380.         if(inout.value.length < 2){
  381.             alert("Input too short");
  382.             return;
  383.         }
  384.         listcell.setAttribute ("label", inout.value);
  385.         listcell.setAttribute ("value", inout.value);
  386.     },
  387.  
  388.  
  389.     listRemoveOnCommand: function  (event)
  390.     {
  391.         document.getElementById ("listRemove").setAttribute ("disabled", true);
  392.         var listBox = document.getElementById ("listBox");
  393.         if (listBox.selectedItem != null)
  394.             listBox.removeChild (listBox.selectedItem);
  395.     },
  396.  
  397.  
  398.     keyDelCookie: function  (event)
  399.     {
  400.         if (event.keyCode == 46) 
  401.             bpriv.DeleteLso();
  402.     },
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410. };